package work.mediway.mdm.biz.dataQuality;

import java.util.Map;

import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import work.mediway.mdm.core.enums.DataQualityExceptionDealTypeEnum;
import work.mediway.mdm.core.exception.BizException;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/11/17
 */
@Slf4j
public class DataQualityDataExceptionDealStrategyFactory {

    private static final Map<DataQualityExceptionDealTypeEnum, DataQualityDataExceptionDealStrategy> DATA_QUALITY_STRATEGY_MAP = MapUtil.newHashMap();

    private static final DataQualityDataExceptionDealStrategy NON_PROMOTION = exceptionDealDTO -> {
        throw new BizException("暂未支持该数据质量异常处理方式");
    };

    static {
        DATA_QUALITY_STRATEGY_MAP.put(DataQualityExceptionDealTypeEnum.IMPORT, new DataQualityDataImportExceptionDealStrategyImpl());
        DATA_QUALITY_STRATEGY_MAP.put(DataQualityExceptionDealTypeEnum.DELETE, new DataQualityDataDeleteExceptionDealStrategyImpl());
        DATA_QUALITY_STRATEGY_MAP.put(DataQualityExceptionDealTypeEnum.IGNORE, new DataQualityDataIgnoreExceptionDealStrategyImpl());
    }

    private DataQualityDataExceptionDealStrategyFactory() {
    }

    /**
     * 通过渠道码获取支付策略具体实现类
     */
    public static DataQualityDataExceptionDealStrategy getStrategy(DataQualityExceptionDealTypeEnum dealType) {
        DataQualityDataExceptionDealStrategy strategy = DATA_QUALITY_STRATEGY_MAP.get(dealType);
        return strategy == null ? NON_PROMOTION : strategy;
    }
}
